﻿#region licence
//  Copyright 2008 Michael Cromwell

//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at

//       http://www.apache.org/licenses/LICENSE-2.0

//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net.Appender;
using Boo.Lang;
using log4net.Core;

namespace log4net.altconf.Tests
{
    public class TestLog4NetDslConfiguration : Log4NetDslConfiguration
    {
        private IList<Action<string, Action>> logForCallbacks = new System.Collections.Generic.List<Action<string, Action>>();
        private IList<Action<string[]>> useAppendersCallbacks = new System.Collections.Generic.List<Action<string[]>>();
        private IList<Action<Level>> atLevelCallbacks = new System.Collections.Generic.List<Action<Level>>();
        private IList<Action<string, Type>> addAppenderCallbacks = new System.Collections.Generic.List<Action<string, Type>>();

        public void ListenForLogFor(Action<string, Action> callback)
        {
            logForCallbacks.Add(callback);
        }

        public void ListenForUseAppenders(Action<string[]> callback)
        {
            useAppendersCallbacks.Add(callback);
        }

        public void ListenForAtLevel(Action<Level> callback)
        {
            atLevelCallbacks.Add(callback);
        }

        public void ListenForAddAppender(Action<string, Type> callback)
        {
            addAppenderCallbacks.Add(callback);
        }
        
        public override void LogFor(string name, Action action)
        {
            base.LogFor(name, action);
            foreach (var item in logForCallbacks)
                item(name, action);
        }

        public override void UseAppenders(params string[] appenders)
        {
            base.UseAppenders(appenders);
            foreach (var item in useAppendersCallbacks)
                item(appenders);
        }

        public override void AtLevel(Level level)
        {
            base.AtLevel(level);
            foreach (var item in atLevelCallbacks)
                item(level);
        }

        public override void AddAppender(string name, Type type)
        {
            base.AddAppender(name, type);
            foreach (var item in addAppenderCallbacks)
                item(name, type);
        }

        public override void Process()
        {
            // no op
        }

        public IAppender GetAppender(string name)
        {
            return appenders[name];
        }

        public LogDetails CurrentLog
        {
            get { return currentLog; }
        }
        
        public override void IgnoreInheritedAppenders()
        {
            base.IgnoreInheritedAppenders();
        }
    }
}
